<style>
    .layui-form .layui-form-item .layui-inline .layui-form-label {
        width: 150px;
    }
</style>
<form class="layui-form seller-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">Ip：</label>
            <div class="layui-input-inline seller-inline-3">
                <input type="text" name="ip" lay-verify="title" placeholder="name" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="*"><i class="iconfont icon-chaxun"></i>Search</button>
            </div>
        </div>
    </div>
</form>

<div class="table-body">
    <table id="balanceTable" lay-filter="balanceTable"></table>
</div>
<script>
    layui.use(['form', 'table',], function () {
        var form = layui.form,
            table = layui.table; //表格

        table.render({
            elem: '#balanceTable',
            height: 'full-99',
            cellMinWidth: '80',
            // totalRow: true,
            method: 'post',
            url: "{:url('user/deviceList')}",
            id: 'balanceTable',
            text:{none: 'No Data'},
            cols: [[
                { type: 'numbers'},
                { field: 'ip', align: 'center', title: 'IP Address'},
                { align: 'center', title: 'Authorization Date' ,
                    templet: function (d) {
                        return layui.util.toDateString(d.ctime * 1000, "yyyy-MM-dd HH:mm:ss");
                    }
                },
                { align: 'center', title: 'Last sign in' ,
                    templet: function (d) {
                        return layui.util.toDateString(d.ctime * 1000, "yyyy-MM-dd HH:mm:ss");
                    }
                },
                { field: 'option', title: 'action',
                    templet: function (d) {
                        var html = '<a class="layui-btn layui-btn-xs layui-btn-danger option-del" data-id="' + d.id + '" >Delete</a>';
                        return html;
                    }, align: 'center'
                }
            ]],
            page: true,
            limit: 20,
            limits: [20, 50, 100],
        });
        form.on('submit(*)', function (data) {
            layui.table.reload('balanceTable', {
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        //删除
        $(document).on('click', '.option-del', function () {
            var id = $(this).attr('data-id');
            layer.confirm('Are you sure you want to delete it?', {
                title:'Window' , btn: ['confirm', 'cancel'], //按钮
            }, function () {
                //去删除
                JsPost("{:url('user/deviceDel')}", { 'id': id }, function (res) {
                    if (res.code) {
                        layer.msg('successfully delete.');
                        layui.table.reload('balanceTable');
                    } else {
                        layer.msg('fail to delete');
                    }
                });
            }, function () {
                layer.close(1);
            });
        });
    });
</script>